package com.huawei.cloud.phone.management.domain.connection;

import com.huawei.cloud.phone.management.common.utils.RandomStringUtils;
import com.huawei.cloud.phone.management.domain.phone.Phone;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Data
public class Connection {
    private String connectionId;

    private String userPhoneId;

    private String phoneId;

    private String sessionId;

    private ConnectionStatus status;

    private Phone phone;

    private ConnectionParam connectionParam;

    public Connection(Phone phone, String userPhoneId) {
            this.status = ConnectionStatus.CONNECTED;
        this.sessionId = RandomStringUtils.randomUuidNoHyphens();
        this.userPhoneId = userPhoneId;
        this.phoneId = phone.getPhoneId();
        this.phone = phone;
    }

    public boolean isValid() {
        return this.status != ConnectionStatus.IDLE;
    }

    public void refresh() {
        this.status = ConnectionStatus.CONNECTED;
        this.sessionId = RandomStringUtils.randomUuidNoHyphens();
    }
}
